package fr.umlv.m2.uwp2011.web.client.professor;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

import fr.umlv.m2.uwp2011.service.sujet.DisplayTD;
import fr.umlv.m2.uwp2011.web.client.Application;
import fr.umlv.m2.uwp2011.web.client.Session;

public class ProfessorTeachingTD extends Composite {
	/**
	 * The course title.
	 */
	private final Label title;
	/**
	 * The course description.
	 */
	private final Label description;

	/**
	 * The download link.
	 */
	private final Hyperlink download;
	/**
	 * The edit link.
	 */
	private final Hyperlink edit;
	/**
	 * The delete link.
	 */
	private final Hyperlink delete;
	/**
	 * The links panel.
	 */
	private final HorizontalPanel linksPagePanel;

	/**
	 * The page panel.
	 */
	private final VerticalPanel pagePanel;

	/**
	 * The main panel.
	 */
	private final VerticalPanel page;

	public ProfessorTeachingTD(Long cursus_id, DisplayTD td, Session session, int matiere_index) {
		/****************************** Widgets Creation ******************************/
		this.title = new Label(td.getTitre());
		this.description = new Label();

		this.download = new Hyperlink("Télécharger", "#");
		this.edit = new Hyperlink("Editer",
                Application.PROFESSOR_EDITOR + "?login=" + session.getParameters().get("login") +
                "&key=" + session.getParameters().get("key") +
                "&cursus=" + cursus_id +
                "&td=" + td.getId() 
            );
		this.delete = new Hyperlink("Supprimer",
                Application.PROFESSOR_TEACHING + "?login=" + session.getParameters().get("login") +
                "&key=" + session.getParameters().get("key") +
                "&cursus=" + cursus_id +
                "&delete_td=" + td.getId() +
                "&matiere_index=" + matiere_index
            );
		this.linksPagePanel = new HorizontalPanel();

		this.pagePanel = new VerticalPanel();
		this.page = new VerticalPanel();

		/*************************** Widgets initialization ***************************/    
		this.description.setText(td.getDescription());

		/******************************** Widgets style *******************************/
		this.page.setWidth("745px");
		this.pagePanel.setWidth("725px");
		this.pagePanel.addStyleName("professorTeachingCoursPagePanel");

		this.title.addStyleName("professorTeachingCoursTitle");
		this.description.addStyleName("professorTeachingCoursDescription");

		this.download.addStyleName("professorTeachingCoursLink");
		this.edit.addStyleName("professorTeachingCoursLink");
		this.delete.addStyleName("professorTeachingCoursLink");

		/******************************** Page building *******************************/
		this.linksPagePanel.add(this.download);
		this.linksPagePanel.add(this.edit);
		this.linksPagePanel.add(this.delete);

		this.pagePanel.add(this.title);
		this.pagePanel.add(this.description);
		this.pagePanel.add(this.linksPagePanel);

		this.page.add(this.pagePanel);
		this.initWidget(this.page);
	}
}
